package com.guomao.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {

    //    localhost:8080/web/user/login
    //    localhost:8080/web/manager/login
    @RequestMapping(value = "/login")
    public String login(Model m) {

        m.addAttribute("msg", "welcome springmvc! user");
        return "login";
    }


//    @RequestMapping(value = "/logout")
//    @RequestMapping(value = "/logout",method = RequestMethod.POST)

    @GetMapping("/logout")
//    @PostMapping
//    @DeleteMapping
//    @PutMapping
    public String logout(Model m) {
        m.addAttribute("msg", "welcome springmvc! method...");
        return "logout";
    }

    //    @RequestMapping(value = "/show",params = {"username"})
//    @RequestMapping(value = "/show",params = {"username!=admin"})
    @RequestMapping(value = "/show", headers = {"User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0"})
    public String show(Model m) {
        m.addAttribute("msg", "welcome springmvc! headers...");
        return "logout";
    }

/*    @RequestMapping("/test")
    public String test(HttpServletRequest request) {
        String username = request.getParameter("username");
        request.setAttribute("username", username);
        return "logout";
    }*/


    //http://localhost:8080/mvc/user/test/root

    @RequestMapping({"/test/{username}", "/test"})
    public String test(HttpServletRequest request,
                       @PathVariable(value = "username", required = false)
                       String username) {
//        String username = request.getParameter("username");
        request.setAttribute("username", username);
        return "logout";
    }
}
